//  ViewController.swift
//  UIStepperAndUISliderDemo

//  Created by itshizhan on 2020/11/3.
//  Copyright © 2020 itshizhan. All rights reserved.

import UIKit

class ViewController: UIViewController {
	
	lazy var label: UILabel = {
		let lable = UILabel()
		lable.frame = CGRect(x: 20, y: 64, width: 200, height: 40)
		lable.textColor = UIColor.black
		return lable
	}()
	
	lazy var stepper:UIStepper = {
		let stepper = UIStepper()
		stepper.frame = CGRect(x: 40, y: 130, width: 100, height: 40)
		//添加事件
		stepper.addTarget(self, action: #selector(ViewController.onStepperValueChange(_:)), for: .valueChanged)
		//设置初始值
		stepper.value = 1.0
		//触发形式
		stepper.isContinuous = false
		stepper.maximumValue = 10.0
		stepper.minimumValue = 1.0
		//可以循环
		stepper.wraps = true
		// 每次加减2
		stepper.stepValue = 2
		
		//背景颜色
		//stepper.backgroundColor = UIColor.gray
		//边框颜色,无效
		stepper.tintColor = UIColor.red
		//改变大小
		stepper.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
		

		return stepper
		
	}()
	
	lazy var slider:UISlider = {
		let slider = UISlider()
		slider.frame = CGRect(x: 20, y: 200, width: 200, height: 40)
		//添加事件
		slider.addTarget(self, action: #selector(ViewController.onSliderValueChange(_:)), for: .valueChanged)
		//设置初始值
		slider.value = 1.0
		//触发形式
		slider.isContinuous = false
		slider.maximumValue = 10.0
		slider.minimumValue = 1.0
		slider.minimumTrackTintColor = UIColor.red
		slider.maximumTrackTintColor = UIColor.orange

		return slider
		
	}()

	override func viewDidLoad() {
		super.viewDidLoad()
		view.addSubview(label)
		view.addSubview(stepper)
		view.addSubview(slider)
		//显示计步器的初始值到lable 上
		label.text = "计步器的值：\(stepper.value)"
		
	}

	@objc
	func onStepperValueChange(_ stepper:UIStepper) {
		// 一直点击增加：依次循环输出1、3、5、7、9、13、5、7、9
		print("stepper value:\(stepper.value)")
		label.text = "计步器的值：\(stepper.value)"
	}

	@objc
	func onSliderValueChange(_ slider:UISlider) {
		print("Slider value:\(slider.value)")
	}
}

